package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.common.constant.ResultCodeEnum;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.GoodsDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.GoodsCommandNew_whh;
import com.cskaoyan.wordmemorize.request.GoodsPageRequest;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.service.GoodsService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/goods")
public class ProductController_whh {
    @Resource
    GoodsService goodsService;


    @PostMapping
    public Result addGoods(@RequestBody GoodsCommandNew_whh command) {

        goodsService.addGoods(command);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }

    @PutMapping
    public Result putGoods(@RequestBody GoodsCommandNew_whh command) {
        goodsService.updateGoods(command);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }

    @GetMapping("list")
    public Result<PageDTO<GoodsDTO>> listGoods(GoodsPageRequest pageRequest) {
        PageDTO<GoodsDTO> goodsPage = goodsService.getGoodsPage(pageRequest);
        return Result.ok(goodsPage);
    }

    @PutMapping("status/{goodsId}")
    public Result putStatus(@PathVariable Long goodsId, Integer status) {
        goodsService.updateGoodsStatus(goodsId, status);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }

    @DeleteMapping("{goodsId}")
    public Result deleteGoods(@PathVariable Long goodsId) {
        goodsService.deleteGoods(goodsId);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }

    @DeleteMapping("selected")
    public Result deleteGoodsList(@RequestBody BatchDeleteCommand command) {
        goodsService.deleteGoodsSelected(command);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }
}
